var RANDOM = '?rand=v1.0.54',
    libURL = 'http://res1.hubcloud.com.cn/';
app.config(function($stateProvider,$urlRouterProvider,$urlServiceProvider,$ocLazyLoadProvider) {
    //  代理商
    var agent = ["agReportEffect","agBaseInfo","agQualification"
            ,"agAudiences","agTrade","agCreative","agActive","agPeople"
            ,"agOrder","agNewOrder",'agIndex','agNewActive','agReportChange'],
       //其他
        example = ["example", "reward"],
        files = {
            "modules/agent":agent,
            "modules/":example,
        },
        dictionary = setDictionary(files);

    /**
     * 获取modules对象
     * @param files 以文件地址前缀为键,文件名数组为值的对象
     * @returns {Array}
     */
    function setDictionary(files) {
        var dictionary = [];
        for(var path in files ) {
            angular.forEach(files[path], function (data) {
                // 拼接ocLazyLoad的modules所需对象
                var item = {};
                item.name = data;
                item.serie = true;
                item.files = [path+'/'+data + '/'+data+'.css'+RANDOM,path+'/'+data + '/'+data+'Ctrl.js'+RANDOM];
                dictionary.push(item);
            });
        }

        return dictionary;
    };
    $ocLazyLoadProvider.config({
        debug: false,
        events: false,
        modules: dictionary
    });
    var urlRules = $urlServiceProvider.rules;

    urlRules.when("/adv/report","/adv/report/effect");

    $stateProvider
        // 例子
        .state("example",{
            url: '/example',
            templateUrl: 'modules/example/example.html'+RANDOM,
            controller: 'exampleCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        'example',
                        libURL+"lib/beheCalendar/js/behe.js","css/calendar.css",
                        'js/directive.js',
                        'js/checkCalendar.js',"css/checkCalendar.css"
                    ]);
                }]
            }
        })

        .state("reward",{
            url: '/reward',
            templateUrl: 'modules/reward/reward.html'+RANDOM,
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        'reward',
                        'js/directive.js',
                        libURL+'lib/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css',
                        libURL+'lib/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js'
                    ]);
                }]
            }
        })
        //-------------------------代理商页面--------------------------
        .state("agent",{
            url: '/agent/:type/:id',  //0是广告主 1是代理商进入
        })
        //首页
        .state('agent.home',{
            url:'/agIndex',
            templateUrl:'modules/agent/agIndex/agIndex.html'+RANDOM,
            controller:'agentIndexCtrl',
            resolve:{
                des:['$ocLazyLoad',function($ocLazyLoad){
                    return $ocLazyLoad.load([
                        'agIndex',
                        libURL+'lib/echarts/echarts.common.min.js',
                        'js/directive.js',
                    ])
                }]
            }

        })
        //新建活动
        .state('agent.newActive',{
            url:'/agNewActive/:appID',
            templateUrl:'modules/agent/agNewActive/agNewActive.html'+RANDOM,
            controller:'newActiveCtrl',
            resolve:{
                des:['$ocLazyLoad',function($ocLazyLoad){
                    return $ocLazyLoad.load([
                        'agNewActive',
                        libURL+'lib/echarts/echarts.common.min.js',
                        'js/directive.js',
                        libURL+'lib/Datepicker20161107/js/foundation-datepicker.js'
                    ])
                }]
            }

        })

        // 报表
        .state("agent.report",{
            url: '/report',
        })
        // 效果报表
        .state("agent.report.effect",{
            url: '/effect/:activeID/:activeName/:orderID/:orderName',
            templateUrl: 'modules/agent/agReportEffect/agReportEffect.html'+RANDOM,
            controller: 'agReportEffectCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        'agReportEffect',
                        libURL+'lib/echarts/echarts.common.min.js',
                        libURL+"lib/beheCalendar/js/behe.js","css/calendar.css",
                        'js/directive.js'
                    ]);
                }]
            }
        })
        // 合约交易报表
        .state("agent.report.change",{
            url: '/change',
            templateUrl: 'modules/agent/agReportChange/agReportChange.html'+RANDOM,
            controller: 'agReportChangeCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        'agReportChange',
                        //libURL+'lib/echarts/echarts.common.min.js',
                       // libURL+"lib/Datepicker20161107/js/foundation-datepicker.js",
                       //libURL+"lib/Datepicker20161107/js/locales/foundation-datepicker.zh-CN.js",
                       // libURL+"lib/beheCalendar/js/behe.js","css/calendar.css",
                        'js/directive.js',
                    ]);
                }]
            }
        })
        // 系统管理
        .state("agent.manage",{
            url: '/manage',
        })
        // 基本信息
        .state("agent.manage.baseInfo",{
            url: '/baseInfo',
            templateUrl: 'modules/agent/agBaseInfo/agBaseInfo.html'+RANDOM,
            controller: 'agBaseInfoCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load(['agBaseInfo','js/directive.js']);
                }]
            }
        })
        // 资质管理
        .state("agent.manage.qualifications",{
            url: '/qualifications',
            templateUrl: 'modules/agent/agQualification/agQualification.html'+RANDOM,
            controller: 'agQualificationCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load(['agQualification',libURL+'lib/qiniu/qiniuCommen.js','js/directive.js','js/fileUpload.js',"lib/md5.js"]);
                }]
            }
        })
        // 投放管理
        .state("agent.delivery",{
            url: '/delivery',
        })
        // 活动
        .state("agent.delivery.active",{
            url: '/active',
            templateUrl: 'modules/agent/agActive/agActive.html'+RANDOM,
            controller: 'activeCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        'agActive',
                        'js/directive.js',
                        libURL+"lib/beheCalendar/js/behe.js","css/calendar.css"
                    ]);
                }]
            }
        })
        // 人群管理
        .state("agent.delivery.people",{
            url: '/people',
            templateUrl: 'modules/agent/agPeople/agPeople.html'+RANDOM,
            controller: 'agPeopleCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        'agPeople',
                        'js/directive.js'
                    ]);
                }]
            }
        })
        // 订单
        .state("agent.delivery.order",{
            url: '/order',
            templateUrl: 'modules/agent/agOrder/agOrder.html'+RANDOM,
            controller: 'agOrderCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        'agOrder',
                        'js/directive.js',
                        libURL+"lib/beheCalendar/js/behe.js","css/calendar.css"
                    ]);
                }]
            }
        })
        // 订单(带活动过滤)
        .state("agent.delivery.orderFilter",{
            url: '/order/:activeId',
            templateUrl: 'modules/agent/agOrder/agOrder.html'+RANDOM,
            controller: 'agOrderCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        'agOrder',
                        'js/directive.js',
                        libURL+"lib/beheCalendar/js/behe.js","css/calendar.css"
                    ]);
                }]
            }
        })
        // 新建订单
        .state("agent.delivery.newOrder",{
            url: '/newOrder/:oType/:orderId/:activeId',
            templateUrl: 'modules/agent/agNewOrder/agNewOrder.html'+RANDOM,
            controller: 'agNewOrderCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load([libURL+'lib/qiniu/qiniuCommen.js', 'lib/ztree/z_check.css',
                        libURL+'lib/ztree/ztree.min.js','js/directive.js', libURL+'lib/masonry/masonry.pkgd.min.js',
                        libURL+'lib/bootstrap-datetimepicker.js', 'agNewOrder', "js/fileUpload.js", "css/pkg.css","lib/md5.js"]);
                }]
            }
        })
        // app监测
        .state("agent.delivery.audiences",{
            url: '/audiences',
            templateUrl: 'modules/agent/agAudiences/agAudiences.html'+RANDOM,
            controller: 'agAudiencesCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load(['agAudiences','js/directive.js']);
                }]
            }
        })
        // 创意管理
        .state("agent.delivery.creative",{
            url: '/creative',
            templateUrl: 'modules/agent/agCreative/agCreative.html'+RANDOM,
            controller: 'agCreativeCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load(['agCreative','js/directive.js']);
                }]
            }
        })
        // 财务管理
        .state("agent.finance",{
            url: '/finance',
        })
        // 交易记录
        .state("agent.finance.trade",{
            url: '/audiences',
            templateUrl: 'modules/agent/agTrade/agTrade.html'+RANDOM,
            controller: 'agTradeCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load(['agTrade',libURL+"lib/beheCalendar/js/behe.js","css/calendar.css", 'js/directive.js',]);
                }]
            }
        })
})